package org.grottarossa.ui.core;

import java.io.Serializable;

import org.grottarossa.data.DataProvider;
import org.grottarossa.driver.DriverBuilder;
import org.grottarossa.driver.ECMBuilderTemplate;
import org.grottarossa.driver.Identity;
import org.grottarossa.template.drivers.DriverException;
import org.grottarossa.ui.core.layout.LayoutFactory;

import com.vaadin.ui.Window;


/***
 * Mantiene lo stato della sessione applicativa corrente
 * @author 
 *
 */
public class ApplicationSession implements Serializable
{
	/**
	 *
	 */
	private static final long serialVersionUID = 4763535690976530745L;
	private ECMBuilderTemplate m_builder;
	private DataProvider m_dataSourceProvider;
	private LayoutFactory m_layoutFactory;
	private Notifier m_notifier;

	private final String m_user;
	private final String m_password;

	public ApplicationSession(String user, String password, Window mainWindow)
	{
		this.m_user = user;
		this.m_password = password;
		m_notifier = new Notifier(mainWindow);
	}

	public void initialize() throws DriverException
	{
		m_builder = DriverBuilder.build();
		//m_builder.login(new Identity(m_user, m_password));
		m_layoutFactory = new LayoutFactory(this);
		m_dataSourceProvider = new DataProvider(m_builder);
	}

	public ECMBuilderTemplate getBuilder()
	{
		return m_builder;
	}

	public LayoutFactory getLayoutFactory()
	{
		return m_layoutFactory;
	}

	public DataProvider getDataSourceProvider()
	{
		return m_dataSourceProvider;
	}

	public Notifier getNotifier()
	{
		return m_notifier;
	}
}
